package com.qf.fmall2203.index.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.fmall2203.category.entity.Category;
import com.qf.fmall2203.category.service.ICategoryService;
import com.qf.fmall2203.index.entity.IndexImg;
import com.qf.fmall2203.index.service.IIndexImgService;
import com.qf.fmall2203.product.entity.Product;
import com.qf.fmall2203.product.service.IProductService;
import com.qf.fmall2203.utils.ResultVo;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 轮播图  前端控制器
 * </p>
 *
 * @author dongjl
 * @since 2023-02-14
 */
@CrossOrigin
@RestController
@RequestMapping("/index")
public class IndexImgController {

    @Autowired
    IIndexImgService indexImgService;

    @Autowired
    ICategoryService categoryService;

    @Autowired
    IProductService productService;

    @GetMapping("/category-recommends")
    public ResultVo categoryRecommends(){

        List<Category> data = categoryService.categoryRecommends();

        return ResultVo.ok(data);

    }


    /**
     * 首页最新上架商品推荐
     */
    @GetMapping("/list-recommends")
    public ResultVo listRecommends(){

        List<Product> data = productService.listRecommends();

        return ResultVo.ok(data);


    }


    /**
     * 首页轮播图
     * @return
     */
    @GetMapping("/indeximg")
    public ResultVo indeximg(){

        final List<IndexImg> data = indexImgService.list(new QueryWrapper<IndexImg>()
                .eq("status", 1)
                .orderByAsc("seq"));

        return ResultVo.ok(data);

    }


    /**
     * 首页分类信息
     */

    @GetMapping("/category-list")
    public ResultVo categoryList(){

//        List<Category> data =  categoryService.categoryList();
//        List<Category> data = categoryService.categoryListBySql();
//        final List<Category> data = categoryService.categoryListRecursive();

        final List<Category> data = categoryService.categoryListRecursiveBetter();

        return ResultVo.ok(data);

    }


}
